import Vue from 'vue'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'
import '@wangeditor/editor/dist/css/style.css' // 引入 css
import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log
import JsonExcel from 'vue-json-excel'
Vue.component('downloadExcel', JsonExcel)
import moment from 'moment'
Vue.prototype.$moment = moment

import * as filters from './filters' // global filters

import CopyItem from '@/components/Template/Common/CopyItem'
Vue.component(CopyItem.name, CopyItem)
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor)
import vueWaves from './directive/waves'
Vue.use(vueWaves)
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

Element.Switch.props.activeValue.default = 1
Element.Switch.props.inactiveValue.default = 0
Element.Switch.props.activeColor.default = '#13ce66'

Element.Drawer.props.wrapperClosable.default = false

Vue.use(Element, {
  size: 'mini' // set element-ui default size
  // locale: enLang // 如果使用中文，无需设置，请删除
})
let messageBox = null

Vue.$sydMessage = Vue.prototype.$sydMessage = {
  info: (msg) => {
    clearMessageBox()
    messageBox = Element.Message({
      type: 'info',
      message: msg,
      dangerouslyUseHTMLString: true
    })
  },
  success: (msg) => {
    clearMessageBox()
    messageBox = Element.Message.success({
      type: 'success',
      message: msg,
      dangerouslyUseHTMLString: true
    })
  },
  warning: (msg) => {
    clearMessageBox()
    messageBox = Element.Message.warning({
      type: 'warning',
      message: msg,
      dangerouslyUseHTMLString: true
    })
  },
  error: (msg) => {
    clearMessageBox()
    messageBox = Element.Message.error({
      type: 'error',
      message: msg,
      dangerouslyUseHTMLString: true
    })
  }
}

function clearMessageBox() {
  if (messageBox === null) return

  messageBox.close()
  messageBox = null
}

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
